package com;

import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class TestServlet extends HttpServlet {
    public static String videopath = null;
    private final Gson om = new Gson();
    private int count = 0;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");//设置成返回html页面
        response.setCharacterEncoding("utf-8");
        String tmp = "http://localhost:8080/video/";//
        count++;
        if (count % 5 == 0) {
            videopath = tmp + "1.mp4";
        } else if (count % 8 == 0) {
            videopath = tmp + "2.mp4";
        }
        if (videopath != null) {
            String s = om.toJson(videopath);
            videopath = null;
            PrintWriter writer = response.getWriter();
            writer.print(s);
            writer.flush();
            writer.close();
        }
    }
}
